home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / bin / ldd < prev    next >
Encoding:
Text File  |  2012-06-08  |  5.1 KB  |  194 lines

  1. #! /bin/bash
  2. # Copyright (C) 1996-2008, 2009 Free Software Foundation, Inc.
  3. # This file is part of the GNU C Library.
  4.  
  5. # The GNU C Library is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 2.1 of the License, or (at your option) any later version.
  9.  
  10. # The GNU C Library is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. # Lesser General Public License for more details.
  14.  
  15. # You should have received a copy of the GNU Lesser General Public
  16. # License along with the GNU C Library; if not, write to the Free
  17. # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. # 02111-1307 USA.
  19.  
  20.  
  21. # This is the `ldd' command, which lists what shared libraries are
  22. # used by given dynamically-linked executables.  It works by invoking the
  23. # run-time dynamic linker as a command and setting the environment
  24. # variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
  25.  
  26. # We should be able to find the translation right at the beginning.
  27. TEXTDOMAIN=libc
  28. TEXTDOMAINDIR=/usr/share/locale
  29.  
  30. RTLDLIST="/lib/ld-linux.so.2 /lib64/ld-linux-x86-64.so.2"
  31. warn=
  32. bind_now=
  33. verbose=
  34.  
  35. while test $# -gt 0; do
  36.   case "$1" in
  37.   --vers | --versi | --versio | --version)
  38.     echo 'ldd (Debian EGLIBC 2.11.3-4) 2.11.3'
  39.     printf $"Copyright (C) %s Free Software Foundation, Inc.
  40. This is free software; see the source for copying conditions.  There is NO
  41. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  42. " "2009"
  43.     printf $"Written by %s and %s.
  44. " "Roland McGrath" "Ulrich Drepper"
  45.     exit 0
  46.     ;;
  47.   --h | --he | --hel | --help)
  48.     printf $"Usage: ldd [OPTION]... FILE...
  49.       --help              print this help and exit
  50.       --version           print version information and exit
  51.   -d, --data-relocs       process data relocations
  52.   -r, --function-relocs   process data and function relocations
  53.   -u, --unused            print unused direct dependencies
  54.   -v, --verbose           print all information
  55. "
  56.     printf $"For bug reporting instructions, please see:
  57. %s.
  58. " "<http://www.debian.org/Bugs/>"
  59.     exit 0
  60.     ;;
  61.   -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
  62.   --data-rel | --data-relo | --data-reloc | --data-relocs)
  63.     warn=yes
  64.     shift
  65.     ;;
  66.   -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
  67.   --function | --function- | --function-r | --function-re | --function-rel | \
  68.   --function-relo | --function-reloc | --function-relocs)
  69.     warn=yes
  70.     bind_now=yes
  71.     shift
  72.     ;;
  73.   -v | --verb | --verbo | --verbos | --verbose)
  74.     verbose=yes
  75.     shift
  76.     ;;
  77.   -u | --u | --un | --unu | --unus | --unuse | --unused)
  78.     unused=yes
  79.     shift
  80.     ;;
  81.   --v | --ve | --ver)
  82.     echo >&2 $"ldd: option \`$1' is ambiguous"
  83.     exit 1
  84.     ;;
  85.   --)        # Stop option processing.
  86.     shift; break
  87.     ;;
  88.   -*)
  89.     echo >&2 'ldd:' $"unrecognized option" "\`$1'"
  90.     echo >&2 $"Try \`ldd --help' for more information."
  91.     exit 1
  92.     ;;
  93.   *)
  94.     break
  95.     ;;
  96.   esac
  97. done
  98.  
  99. nonelf ()
  100. {
  101.   # Maybe extra code for non-ELF binaries.
  102.   return 1;
  103. }
  104.  
  105. add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
  106. add_env="$add_env LD_LIBRARY_VERSION=\$verify_out"
  107. add_env="$add_env LD_VERBOSE=$verbose"
  108. if test "$unused" = yes; then
  109.   add_env="$add_env LD_DEBUG=\"$LD_DEBUG${LD_DEBUG:+,}unused\""
  110. fi
  111.  
  112. # The following use of cat is needed to make ldd work in SELinux
  113. # environments where the executed program might not have permissions
  114. # to write to the console/tty.  But only bash 3.x supports the pipefail
  115. # option, and we don't bother to handle the case for older bash versions.
  116. if x=`set -o` && test "$x" != "${x#*pipefail}" && set -o pipefail ; then
  117.   try_trace() {
  118.     eval $add_env '"$@"' | cat
  119.   }
  120. else
  121.   try_trace() {
  122.     eval $add_env '"$@"'
  123.   }
  124. fi
  125.  
  126. case $# in
  127. 0)
  128.   echo >&2 'ldd:' $"missing file arguments"
  129.   echo >&2 $"Try \`ldd --help' for more information."
  130.   exit 1
  131.   ;;
  132. 1)
  133.   single_file=t
  134.   ;;
  135. *)
  136.   single_file=f
  137.   ;;
  138. esac
  139.  
  140. result=0
  141. for file do
  142.   # We don't list the file name when there is only one.
  143.   test $single_file = t || echo "${file}:"
  144.   case $file in
  145.   */*) :
  146.        ;;
  147.   *) file=./$file
  148.      ;;
  149.   esac
  150.   if test ! -e "$file"; then
  151.     echo "ldd: ${file}:" $"No such file or directory" >&2
  152.     result=1
  153.   elif test ! -f "$file"; then
  154.     echo "ldd: ${file}:" $"not regular file" >&2
  155.     result=1
  156.   elif test -r "$file"; then
  157.     RTLD=
  158.     ret=1
  159.     for rtld in ${RTLDLIST}; do
  160.       if test -x $rtld; then
  161.     verify_out=`${rtld} --verify "$file"`
  162.         ret=$?
  163.     case $ret in
  164.     [02]) RTLD=${rtld}; break;;
  165.     esac
  166.       fi
  167.     done
  168.     case $ret in
  169.     0|2)
  170.       try_trace "$RTLD" "$file" || result=1
  171.       ;;
  172.     1|126)
  173.       # This can be a non-ELF binary or no binary at all.
  174.       nonelf "$file" || {
  175.     echo $"    not a dynamic executable"
  176.     result=1
  177.       }
  178.       ;;
  179.     *)
  180.       echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
  181.       exit 1
  182.       ;;
  183.     esac
  184.   else
  185.     echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2
  186.     result=1
  187.   fi
  188. done
  189.  
  190. exit $result
  191. # Local Variables:
  192. #  mode:ksh
  193. # End:
  194.